<template>
  <el-aside :width="width" class="aside-container">
    <el-menu
      :default-active="activePath"
      :collapse="isCollapse"
      :collapse-transition="false"
      style="border: none"
    >
      <h3 v-show="!isCollapse" style="margin-left: 10px">社区养老互助平台</h3>
      <h3 v-show="isCollapse" style="margin-left: 10px">后台</h3>
      <el-menu-item
        v-for="item in noChildren"
        :key="item.path"
        :index="item.path"
        @click="navigate(item)"
      >
        <component class="icons" :is="item.icon"></component>
        <span>{{ item.title }}</span>
      </el-menu-item>
      <el-sub-menu
        v-for="item in hasChildren"
        :key="item.path"
        :index="item.path"
      >
        <template #title>
          <component class="icons" :is="item.icon"></component>
          <span>{{ item.title }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            v-for="subItem in item.children"
            :index="subItem.path"
            :key="subItem.path"
            @click="navigate(subItem)"
          >
            <span> {{ subItem.title }}</span>
          </el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu>
  </el-aside>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router';
import menuConfig from '../utils/menuConfig.js';
import { useHomeDataStore } from '../stores/index.js';
import { computed } from 'vue';
// 得到路由数组进行遍历
const route = useRoute();
const router = useRouter();
const activePath = route.path;
const store = useHomeDataStore();``
// 通过点击事件来进行路由跳转
const navigate = (menu) => {
  router.push(menu.path);
  store.selectMenu(menu);
};
// 得到 stores

const isCollapse = computed(() => {
  return store.state.isCollapse;
});
console.log(isCollapse);
// 宽度
const width = computed(() => (store.state.isCollapse ? '60px' : '200px'));

const noChildren = menuConfig.filter((item) => !item.children);
const hasChildren = menuConfig.filter((item) => item.children);

</script>

<style scoped lang="less">
.icons {
  width: 24px !important; /* 固定宽度 */
  height: 24px !important; /* 固定高度 */
  margin-right: 12px;
  color: #555; /* 图标颜色 */
  transition: none; /* 不跟随菜单宽度变化 */

}
.aside-container {
  margin-right: 0px;
  border: 1px solid #dcdfe6; /* 固定边框样式 */
  height: 100vh; /* 设置固定高度为 100% 视口高度 */
  box-shadow: 0 4px 8px rgb(255, 255, 255), 0 -4px 8px rgb(83, 84, 83),
    4px 0 8px rgba(0, 0, 0, 0.1); /* 去掉左边的阴影 */

  position: fixed; /* 固定定位，使其漂浮在页面上 */
  top: 0;
  left: 20px;
  z-index: 10; /* 确保在其他内容之上 */
  transition: none; /* 保证宽度变化不影响边框 */
  background-color: #fff; /* 背景颜色，确保组件与页面内容区分开 */
}

</style>
